package edu.nf.project.services.accountsAndPermissions.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import edu.nf.project.entitys.entity.accountsAndPermissions.relevancy.Roles_Permissions;
import edu.nf.project.mappers.accountsAndPermissions.relevancy.Roles_PermissionsMapper;
import edu.nf.project.services.accountsAndPermissions.Roles_PermissionsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 角色关联权限 Service 实现类
 */
@Service
public class Roles_PermissionsServiceImpl implements Roles_PermissionsService {
    @Autowired
    private Roles_PermissionsMapper roles_permissionsMapper;

    @Override
    public List<Roles_Permissions> getAll() {
        return roles_permissionsMapper.selectList(null);
    }

    @Override
    public Boolean addP(Integer rId, Integer pId) {
        Roles_Permissions rp = new Roles_Permissions();
        rp.setRId(rId);
        rp.setPId(pId);
        return roles_permissionsMapper.insert(rp) > 0;
    }

    @Override
    @Transactional
    public Boolean delP(Integer rId, Integer pId) {
        LambdaQueryWrapper<Roles_Permissions> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Roles_Permissions::getRId, rId)
                .eq(Roles_Permissions::getPId, pId);
        int result = roles_permissionsMapper.delete(queryWrapper);
        return result > 0;
    }
}
